const useIdel = (times, task) => {
  let i = 0
  const callBack = (IdleDeadline) => {
    const getTimeOut = () => IdleDeadline.timeRemaining()
    const hasTime = () => getTimeOut() > 1
    console.log('callBack', getTimeOut())
    while (hasTime() && i < times) {
      i++
      task()
    }
    i < times && requestIdleCallback(callBack)
  }
  requestIdleCallback(callBack)
}
// 02.使用这种方法流畅
// useIdel(100000, () => {
//   console.log('run task')
// })

// 01.使用这种方法占用主线程不流畅
// let i = 0
// while (i++ < 100000) {
//   console.log('9')
// }
